package com.ibt.controller;


	
	
	import java.util.Date;

	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import javax.servlet.http.HttpSession;

	import org.springframework.stereotype.Controller;
	import org.springframework.web.bind.annotation.RequestMapping;
	import org.springframework.web.bind.annotation.RequestMethod;
	import org.springframework.web.bind.annotation.RequestParam;
	import org.springframework.web.servlet.ModelAndView;

import com.ibt.dao.BuildIdsDAO;
	import com.ibt.dao.ModuleDAO;
	import com.ibt.dao.ProjectEntryDAO;
import com.ibt.entity.BuildIds;
	import com.ibt.entity.Business;
	import com.ibt.entity.Login;
	import com.ibt.entity.Module;
import com.ibt.entity.ProjectEntry;

	@Controller
	@RequestMapping("/buildid")
public class BuildIdController {
		@RequestMapping(value="/add.do",method = RequestMethod.POST)
		public ModelAndView userEntry(@RequestParam("pname") String pname, 
				@RequestParam("mname") String manme,  
				ModelAndView model,HttpSession session,HttpServletRequest req,HttpServletResponse res) throws Exception {
			String rcount=req.getParameter("rowcount");
			int rowcount=Integer.parseInt(rcount);
			System.out.println("row count "+rowcount);
			Business bus=(Business)session.getAttribute("business");
			Login  Ulogin=(Login)session.getAttribute("user");
			int busId=bus.getBusinessId();
			
			ProjectEntry project=ProjectEntryDAO.getByName(pname, busId);
			Module module=ModuleDAO.getByName(pname, manme, busId);
	System.out.println("the module id info is"+module);
		
			for(int i=1;i<=rowcount;i++){
				String build=req.getParameter("build"+i);
				String bdesc=req.getParameter("bdesc"+i);
				String devname=req.getParameter("devname"+i);
				BuildIds bildId=null;
				try {
					 bildId=new BuildIds(bus,project,module,build,bdesc,devname);
				} catch (NullPointerException e) {
					e.printStackTrace();
				}
				BuildIdsDAO.insert(bildId);
			}
	   
			System.out.println("in x0029 searching  BusinessUserid " );
			model.setViewName("/jsp/addproject.jsp");
			model.addObject("msg","New Project is Added to The System with ProjectName:"+pname);
			return model;

	}
		

	}


